#include <iostream>
#include <vector>
#include "hw2.h"
#include <math.h>
#include <iomanip>
using namespace std;

double Function :: operator()(double _x)
{
    return 1/(1+_x*_x);
}
//因为未用到导数，所以全取0
int main()
{
    //cout << "B题测试结果:" << endl;
    Function f;
    int n[4]={2,4,6,8};
    for(int m = 0; m < 4; m++)
    {
        double x[n[m]+1];
        double y[n[m]+1];
        Point points[n[m]+1];
        for(int i = 1; i <= n[m]+1; i++)
        {
            x[i-1] = -5+10.0*(i-1)/n[m];
            y[i-1] = f(x[i-1]);
            //cout << x[i-1] << endl;
            Point p(x[i-1],y[i-1],0);
            points[i-1] = p;
        }
        init(points,n[m]+1);
        //cout << "当n=" << n[m] << "时，牛顿插值多项式系数为:" << endl;
        //cout << h_gdq(1) << endl;
        //cout << h_gdq(3,3) << endl;
        for (int i = 0; i < n[m]+1; i++)
        {
            //double a = gdq(i);
            double a = h_gdq(i+1,n[m]+2);
            cout << a << endl;
        }
    }
    
    return 0;  
}
